package liy.demo.wikiproject.config;

import jakarta.annotation.Resource;
import liy.demo.wikiproject.interceptor.LogInterceptor;
import liy.demo.wikiproject.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
    @Resource
    LogInterceptor logInterceptor;
    @Resource
    LoginInterceptor loginInterceptor;
//    @Override
//    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
//        resolvers.add(new CustomExceptionResolver());
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor)
                .addPathPatterns("/**");
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/category/all"
                        ,"/doc/all",
                        "/ebook/list",
                        "/ebook/list/category",
                "/doc/document/content"
                ,"/user/login/**","/favicon.ico",
                        "/error"
                        );

    }
}
